package Demo3;

import java.util.Scanner;

class List {
    String name;
    int level;
    int run_time;

    public List(String name, int level, int run_time) {
        this.name = name;
        this.level = level;
        this.run_time = run_time;
    }

}

public class Array {


    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int len = s.nextInt();
        List[] list = new List[len];
        for (int i = 0; i < len; i++) {
            String name = s.next();
            int level = s.nextInt();
            int run_time = s.nextInt();
            list[i] = new List(name, level, run_time);
        }
        int listEnd = len;
        while (listEnd > 0) {
            int pos = Max_Level(list);
            System.out.print(list[pos].name + " ");
            list[pos].level--;
            list[pos].run_time--;
            if (list[pos].run_time == 0) {
                listEnd--;
            }
            if (list[pos].level < 0) {
                list[pos].level = 0;
            }
        }
    }
    public static int Max_Level(List[] data) {
        int max_level = 0, i = 0;
        for (; i < data.length; i++) {
            if (data[i].run_time != 0) {
                max_level = data[i].level;
                break;
            }
        }
        int pos = i;
        for (int j = 0; j < data.length; j++) {
            if (data[j].run_time == 0) continue;
            if (max_level < data[j].level) {
                max_level = data[j].level;
                pos = j;
            }
        }
        return pos;
    }
}
